### CODE FOR:
###
### Partisan Influence on Policy Preferences 
### When Parties and Voters Disagree on Welfare Retrenchment
###
### PART 3: Barplots (Figure 2 & Figure A3)
###
### VERSION: 2024-FEB-23


rm(list=ls())
gc()



# WORKING DIRECTORY -------------------------------------------------------
setwd("C:/Users/miros/Desktop/Research/Finland - Partisan Cues in Citizens Attitudes")



# LIBRARIES ---------------------------------------------------------------
library(ggplot2)
library(RColorBrewer)
library(grid)
library(ggpubr)
library(dplyr)




# DATA IMPORT -------------------------------------------------------------
# NOTE: The data file loaded in the next step was prepared in a separate
#       scripts '01_PartyCues-data_prep.R'. If you haven't run the script, 
#       return to the depository and run that script first. Its output is 
#       'BIBU_long.Rda' loaded in the next step.
load("01-data/BIBU_long.Rda")
load("01-data/BIBU_panel.Rda")





# FIGURE B1 ---------------------------------------------------------------

# _ Subsetting relevant data ----------------------------------------------
# NOTE: Used are only observations of those participants for whom dataset
#       includes information on party vote (in both rounds) and left-right
#       ideology (in both rounds)
RETRENCHMENT.both.waves <- na.omit(BIBU.panel[c("PartyChoice.Overall", "RETIREMENT_TUBE_R1", "RETIREMENT_TUBE_R2")])
EXPANSION.both.waves <- na.omit(BIBU.panel[c("PartyChoice.Overall", "COMPULSORY_SCHOOLING_R1", "COMPULSORY_SCHOOLING_R2")])




# _ Generating data.frame with group totals -------------------------------
# NOTE: The following section generates Figure A1 - i.e., a bar plot showing
#       the distribution of individual responses about policy preferences
#       among individual party electorates across two waves

barplot.data <-
  rbind(
    # Welfare retrenchment: Round 1
    data.frame(
      RETRENCHMENT.both.waves %>%
        group_by(Group = PartyChoice.Overall) %>%
        count(Answer = RETIREMENT_TUBE_R1) %>%
        mutate(Group_total = sum(n)) %>%
        mutate(Share = round((n/Group_total)*100, 1)) %>%
        mutate(Reform = c("Retirement Tube"), .before = Group) %>%
        mutate(Round = c("Round 1"), .before = Group)),
    
    # Welfare retrenchment: Round 2
    data.frame(
      RETRENCHMENT.both.waves %>%
        group_by(Group = PartyChoice.Overall) %>%
        count(Answer = RETIREMENT_TUBE_R2) %>%
        mutate(Group_total = sum(n)) %>%
        mutate(Share = round((n/Group_total)*100, 1)) %>%
        mutate(Reform = c("Retirement Tube"), .before = Group) %>%
        mutate(Round = c("Round 2"), .before = Group)),
    
    # Welfare expansion: Round 1
    data.frame(
      EXPANSION.both.waves %>%
        group_by(Group = PartyChoice.Overall) %>%
        count(Answer = COMPULSORY_SCHOOLING_R1) %>%
        mutate(Group_total = sum(n)) %>%
        mutate(Share = round((n/Group_total)*100, 1)) %>%
        mutate(Reform = c("Compulsory Schooling"), .before = Group) %>%
        mutate(Round = c("Round 1"), .before = Group)),
    
    # Welfare expansion: Round 2
    data.frame(
      EXPANSION.both.waves %>%
        group_by(Group = PartyChoice.Overall) %>%
        count(Answer = COMPULSORY_SCHOOLING_R2) %>%
        mutate(Group_total = sum(n)) %>%
        mutate(Share = round((n/Group_total)*100, 1)) %>%
        mutate(Reform = c("Compulsory Schooling"), .before = Group) %>%
        mutate(Round = c("Round 2"), .before = Group))
  )


# Adding line with zero
barplot.data <- rbind(barplot.data,
                      data.frame(Reform = "Compulsory Schooling",
                                 Round = "Round 1",
                                 Group = "Swedish Peoples Party",
                                 Answer = 4,
                                 n = 0,
                                 Group_total = 0,
                                 Share = 0))

# Interim cleanup
rm(RETRENCHMENT.both.waves, 
   EXPANSION.both.waves)





# _ Barplot ---------------------------------------------------------------

# __ Government voters ----------------------------------------------------
ggarrange(
  
  # Left Alliance: Welfare retrenchment
  ggplot(filter(barplot.data, Reform == "Retirement Tube" & Group == "Left Alliance"), 
         aes(x = Answer, y = Share, group = Round, fill = Round)) + 
    # Grid
    geom_hline(yintercept = seq(5, 65, 5), color = "grey90") +
    
    # Bars
    geom_bar(stat = "identity",
             position = position_dodge(),
             color = "black",
             alpha = 0.66) +
    geom_text(aes(label = paste0(Share, "%\nN=", n)), 
              color = "black", 
              size = 2.8, 
              position = position_dodge(0.9), 
              alpha = 0.85, 
              vjust = -0.25, 
              lineheight = 0.8) +
    scale_fill_manual(values = rep(c("#969696", "#525252"), times = 4)) +
    
    # Header
    geom_rect(xmin = 0.35, xmax = 4.65, ymin = 70, ymax = 85, colour = "black", fill = "grey90") +
    annotate("text", x = 2.5, y = 77.5, hjust = 0.5, vjust = -0.15, label = "Welfare retrenchment", size = 12/.pt, fontface = "bold") +
    annotate("text", x = 2.5, y = 77.5, hjust = 0.5, vjust =  1.45, label = "Abolition of the 'retirement tube'", size = 8.5/.pt) +
    
    # Specs
    scale_y_continuous(breaks = seq(0, 70, 10), labels = c("0%", "10%", "20%", "30%", "40%", "50%", "60%", "70%")) +
    scale_x_continuous(breaks = c(1, 2, 3, 4), 
                       labels = c("Strongly\ndisagree","Disagree", "Agree", "Strongly\nagree")) +
    labs(x = NULL, y = NULL, fill = NULL) +
    coord_cartesian(xlim = c(0.35, 4.65), ylim = c(0, 85), expand = FALSE, clip = "off") +
    theme(text = element_text(color = "black"),
          axis.text.x = element_blank(),
          legend.spacing.y = unit(0.25, "cm"),
          legend.key.size = unit(0.65, "cm"),
          panel.grid = element_blank(), 
          panel.background = element_rect(fill = "white"),
          plot.background = element_rect(fill = "white"),
          panel.border = element_rect(fill = "transparent"),
          axis.ticks = element_blank(),
          plot.margin = unit(c(0.2, 0.02, 0.2, 0.2),"cm")),
  
  
  # Left Alliance: Welfare expansion
  ggplot(filter(barplot.data, Reform == "Compulsory Schooling" & Group == "Left Alliance"), 
         aes(x = Answer, y = Share, group = Round, fill = Round)) + 
    # Grid
    geom_hline(yintercept = seq(5, 65, 5), color = "grey90") +
    geom_hline(yintercept = 70) +
    
    # Bars
    geom_bar(stat = "identity",
             position = position_dodge(),
             color = "black",
             alpha = 0.66) +
    geom_text(aes(label = paste0(Share, "%\nN=", n)), 
              color = "black", 
              size = 2.8, 
              position = position_dodge(0.9), 
              alpha = 0.85, 
              vjust = -0.25, 
              lineheight = 0.8) +
    scale_fill_manual(values = rep(c("#969696", "#525252"), times = 4)) +
    
    # Header
    geom_rect(xmin = 0.35, xmax = 4.65, ymin = 70, ymax = 85, colour = "black", fill = "grey90") +
    annotate("text", x = 2.5, y = 77.5, hjust = 0.5, vjust = -0.15, label = "Welfare expansion", size = 12/.pt, fontface = "bold") +
    annotate("text", x = 2.5, y = 77.5, hjust = 0.5, vjust =  1.45, label = "Extension of the compulsory school age", size = 8.5/.pt) +
    
    # Right panel
    geom_rect(xmin = 4.65, xmax = 5.05, ymin = 0, ymax = 70, colour = "black", fill = "grey90") +
    annotate("text", x = 4.85, y = 35, label = "Left Alliance", angle = 270, size = 12/.pt, fontface = "bold") +
    
    # Specs
    scale_y_continuous(breaks = seq(0, 70, 10), labels = c("0%", "10%", "20%", "30%", "40%", "50%", "60%", "70%")) +
    scale_x_continuous(breaks = c(1, 2, 3, 4), labels = c("Strongly\ndisagree","Disagree", "Agree", "Strongly\nagree")) +
    geom_hline(yintercept = 0) + geom_vline(xintercept = 0.35) +
    labs(x = NULL, y = NULL, fill = NULL) +
    coord_cartesian(xlim = c(0.35, 5.05), ylim = c(0, 85), expand = FALSE, clip = "off") +
    theme(text = element_text(color = "black"),
          axis.text.x = element_blank(),
          axis.text.y = element_blank(),
          legend.spacing.y = unit(0.25, "cm"),
          legend.key.size = unit(0.65, "cm"),
          panel.grid = element_blank(), 
          panel.background = element_rect(fill = "white"),
          plot.background = element_rect(fill = "white"),
          panel.border = element_rect(color = "transparent", fill = "transparent"),
          axis.ticks = element_blank(),
          plot.margin = unit(c(0.2, 0.02, 0.2, 0.2),"cm")),
  
  
  # Social democrats: Welfare retrenchment
  ggplot(filter(barplot.data, Reform == "Retirement Tube" & Group == "Social Democrats"), 
         aes(x = Answer, y = Share, group = Round, fill = Round)) + 
    # Grid
    geom_hline(yintercept = seq(5, 65, 5), color = "grey90") +
    
    # Bars
    geom_bar(stat = "identity",
             position = position_dodge(),
             color = "black",
             alpha = 0.66) +
    geom_text(aes(label = paste0(Share, "%\nN=", n)), 
              color = "black", 
              size = 2.8, 
              position = position_dodge(0.9), 
              alpha = 0.85, 
              vjust = -0.25, 
              lineheight = 0.8) +
    scale_fill_manual(values = rep(c("#969696", "#525252"), times = 4)) +
    
    # Specs
    scale_y_continuous(breaks = seq(0, 70, 10), labels = c("0%", "10%", "20%", "30%", "40%", "50%", "60%", "70%")) +
    scale_x_continuous(breaks = c(1, 2, 3, 4), 
                       labels = c("Strongly\ndisagree","Disagree", "Agree", "Strongly\nagree")) +
    labs(x = NULL, y = NULL, fill = NULL) +
    coord_cartesian(xlim = c(0.35, 4.65), ylim = c(0, 70), expand = FALSE, clip = "off") +
    theme(text = element_text(color = "black"),
          axis.text.x = element_blank(),
          legend.spacing.y = unit(0.25, "cm"),
          legend.key.size = unit(0.65, "cm"),
          panel.grid = element_blank(), 
          panel.background = element_rect(fill = "white"),
          plot.background = element_rect(fill = "white"),
          panel.border = element_rect(fill = "transparent"),
          axis.ticks = element_blank(),
          plot.margin = unit(c(0.2, 0.02, 0.2, 0.2),"cm")),
  
  
  # Social democrats: Welfare expansion
  ggplot(filter(barplot.data, Reform == "Compulsory Schooling" & Group == "Social Democrats"), 
         aes(x = Answer, y = Share, group = Round, fill = Round)) + 
    # Grid
    geom_hline(yintercept = seq(5, 65, 5), color = "grey90") +
    geom_hline(yintercept = 70) +
    
    # Bars
    geom_bar(stat = "identity",
             position = position_dodge(),
             color = "black",
             alpha = 0.66) +
    geom_text(aes(label = paste0(Share, "%\nN=", n)), 
              color = "black", 
              size = 2.8, 
              position = position_dodge(0.9), 
              alpha = 0.85, 
              vjust = -0.25, 
              lineheight = 0.8) +
    scale_fill_manual(values = rep(c("#969696", "#525252"), times = 4)) +
    
    # Right panel
    geom_rect(xmin = 4.65, xmax = 5.05, ymin = 0, ymax = 70, colour = "black", fill = "grey90") +
    annotate("text", x = 4.85, y = 35, label = "Social Democrats", angle = 270, size = 12/.pt, fontface = "bold") +
    
    # Specs
    scale_y_continuous(breaks = seq(0, 70, 10), labels = c("0%", "10%", "20%", "30%", "40%", "50%", "60%", "70%")) +
    scale_x_continuous(breaks = c(1, 2, 3, 4), labels = c("Strongly\ndisagree","Disagree", "Agree", "Strongly\nagree")) +
    geom_hline(yintercept = 0) + geom_vline(xintercept = 0.35) +
    labs(x = NULL, y = NULL, fill = NULL) +
    coord_cartesian(xlim = c(0.35, 5.05), ylim = c(0, 70), expand = FALSE, clip = "off") +
    theme(text = element_text(color = "black"),
          axis.text.x = element_blank(),
          axis.text.y = element_blank(),
          legend.spacing.y = unit(0.25, "cm"),
          legend.key.size = unit(0.65, "cm"),
          panel.grid = element_blank(), 
          panel.background = element_rect(fill = "white"),
          plot.background = element_rect(fill = "white"),
          panel.border = element_rect(color = "transparent", fill = "transparent"),
          axis.ticks = element_blank(),
          plot.margin = unit(c(0.2, 0.02, 0.2, 0.2),"cm")),
  
  
  # Greens: Welfare retrenchment
  ggplot(filter(barplot.data, Reform == "Retirement Tube" & Group == "Greens"), 
         aes(x = Answer, y = Share, group = Round, fill = Round)) + 
    # Grid
    geom_hline(yintercept = seq(5, 65, 5), color = "grey90") +
    
    # Bars
    geom_bar(stat = "identity",
             position = position_dodge(),
             color = "black",
             alpha = 0.66) +
    geom_text(aes(label = paste0(Share, "%\nN=", n)), 
              color = "black", 
              size = 2.8, 
              position = position_dodge(0.9), 
              alpha = 0.85, 
              vjust = -0.25, 
              lineheight = 0.8) +
    scale_fill_manual(values = rep(c("#969696", "#525252"), times = 4)) +
    
    # Specs
    scale_y_continuous(breaks = seq(0, 70, 10), labels = c("0%", "10%", "20%", "30%", "40%", "50%", "60%", "70%")) +
    scale_x_continuous(breaks = c(1, 2, 3, 4), 
                       labels = c("Strongly\ndisagree","Disagree", "Agree", "Strongly\nagree")) +
    labs(x = NULL, y = NULL, fill = NULL) +
    coord_cartesian(xlim = c(0.35, 4.65), ylim = c(0, 70), expand = FALSE, clip = "off") +
    theme(text = element_text(color = "black"),
          axis.text.x = element_blank(),
          legend.spacing.y = unit(0.25, "cm"),
          legend.key.size = unit(0.65, "cm"),
          panel.grid = element_blank(), 
          panel.background = element_rect(fill = "white"),
          plot.background = element_rect(fill = "white"),
          panel.border = element_rect(fill = "transparent"),
          axis.ticks = element_blank(),
          plot.margin = unit(c(0.2, 0.02, 0.2, 0.2),"cm")),
  
  
  # Greens: Welfare expansion
  ggplot(filter(barplot.data, Reform == "Compulsory Schooling" & Group == "Greens"), 
         aes(x = Answer, y = Share, group = Round, fill = Round)) + 
    # Grid
    geom_hline(yintercept = seq(5, 65, 5), color = "grey90") +
    geom_hline(yintercept = 70) +
    
    # Bars
    geom_bar(stat = "identity",
             position = position_dodge(),
             color = "black",
             alpha = 0.66) +
    geom_text(aes(label = paste0(Share, "%\nN=", n)), 
              color = "black", 
              size = 2.8, 
              position = position_dodge(0.9), 
              alpha = 0.85, 
              vjust = -0.25, 
              lineheight = 0.8) +
    scale_fill_manual(values = rep(c("#969696", "#525252"), times = 4)) +
    
    # Right panel
    geom_rect(xmin = 4.65, xmax = 5.05, ymin = 0, ymax = 70, colour = "black", fill = "grey90") +
    annotate("text", x = 4.85, y = 35, label = "Greens", angle = 270, size = 12/.pt, fontface = "bold") +
    
    # Specs
    scale_y_continuous(breaks = seq(0, 70, 10), labels = c("0%", "10%", "20%", "30%", "40%", "50%", "60%", "70%")) +
    scale_x_continuous(breaks = c(1, 2, 3, 4), labels = c("Strongly\ndisagree","Disagree", "Agree", "Strongly\nagree")) +
    geom_hline(yintercept = 0) + geom_vline(xintercept = 0.35) +
    labs(x = NULL, y = NULL, fill = NULL) +
    coord_cartesian(xlim = c(0.35, 5.05), ylim = c(0, 70), expand = FALSE, clip = "off") +
    theme(text = element_text(color = "black"),
          axis.text.x = element_blank(),
          axis.text.y = element_blank(),
          legend.spacing.y = unit(0.25, "cm"),
          legend.key.size = unit(0.65, "cm"),
          panel.grid = element_blank(), 
          panel.background = element_rect(fill = "white"),
          plot.background = element_rect(fill = "white"),
          panel.border = element_rect(color = "transparent", fill = "transparent"),
          axis.ticks = element_blank(),
          plot.margin = unit(c(0.2, 0.02, 0.2, 0.2),"cm")),
  
  
  # Centre Party: Welfare retrenchment
  ggplot(filter(barplot.data, Reform == "Retirement Tube" & Group == "Centre Party"), 
         aes(x = Answer, y = Share, group = Round, fill = Round)) + 
    # Grid
    geom_hline(yintercept = seq(5, 65, 5), color = "grey90") +
    
    # Bars
    geom_bar(stat = "identity",
             position = position_dodge(),
             color = "black",
             alpha = 0.66) +
    geom_text(aes(label = paste0(Share, "%\nN=", n)), 
              color = "black", 
              size = 2.8, 
              position = position_dodge(0.9), 
              alpha = 0.85, 
              vjust = -0.25, 
              lineheight = 0.8) +
    scale_fill_manual(values = rep(c("#969696", "#525252"), times = 4)) +
    
    # Specs
    scale_y_continuous(breaks = seq(0, 70, 10), labels = c("0%", "10%", "20%", "30%", "40%", "50%", "60%", "70%")) +
    scale_x_continuous(breaks = c(1, 2, 3, 4), 
                       labels = c("Strongly\ndisagree","Disagree", "Agree", "Strongly\nagree")) +
    labs(x = NULL, y = NULL, fill = NULL) +
    coord_cartesian(xlim = c(0.35, 4.65), ylim = c(0, 70), expand = FALSE, clip = "off") +
    theme(text = element_text(color = "black"),
          axis.text.x = element_blank(),
          legend.spacing.y = unit(0.25, "cm"),
          legend.key.size = unit(0.65, "cm"),
          panel.grid = element_blank(), 
          panel.background = element_rect(fill = "white"),
          plot.background = element_rect(fill = "white"),
          panel.border = element_rect(fill = "transparent"),
          axis.ticks = element_blank(),
          plot.margin = unit(c(0.2, 0.02, 0.2, 0.2),"cm")),
  
  
  # Centre Party: Welfare expansion
  ggplot(filter(barplot.data, Reform == "Compulsory Schooling" & Group == "Centre Party"), 
         aes(x = Answer, y = Share, group = Round, fill = Round)) + 
    # Grid
    geom_hline(yintercept = seq(5, 65, 5), color = "grey90") +
    geom_hline(yintercept = 70) +
    
    # Bars
    geom_bar(stat = "identity",
             position = position_dodge(),
             color = "black",
             alpha = 0.66) +
    geom_text(aes(label = paste0(Share, "%\nN=", n)), 
              color = "black", 
              size = 2.8, 
              position = position_dodge(0.9), 
              alpha = 0.85, 
              vjust = -0.25, 
              lineheight = 0.8) +
    scale_fill_manual(values = rep(c("#969696", "#525252"), times = 4)) +
    
    # Right panel
    geom_rect(xmin = 4.65, xmax = 5.05, ymin = 0, ymax = 70, colour = "black", fill = "grey90") +
    annotate("text", x = 4.85, y = 35, label = "Centre Party", angle = 270, size = 12/.pt, fontface = "bold") +
    
    # Specs
    scale_y_continuous(breaks = seq(0, 70, 10), labels = c("0%", "10%", "20%", "30%", "40%", "50%", "60%", "70%")) +
    scale_x_continuous(breaks = c(1, 2, 3, 4), labels = c("Strongly\ndisagree","Disagree", "Agree", "Strongly\nagree")) +
    geom_hline(yintercept = 0) + geom_vline(xintercept = 0.35) +
    labs(x = NULL, y = NULL, fill = NULL) +
    coord_cartesian(xlim = c(0.35, 5.05), ylim = c(0, 70), expand = FALSE, clip = "off") +
    theme(text = element_text(color = "black"),
          axis.text.x = element_blank(),
          axis.text.y = element_blank(),
          legend.spacing.y = unit(0.25, "cm"),
          legend.key.size = unit(0.65, "cm"),
          panel.grid = element_blank(), 
          panel.background = element_rect(fill = "white"),
          plot.background = element_rect(fill = "white"),
          panel.border = element_rect(color = "transparent", fill = "transparent"),
          axis.ticks = element_blank(),
          plot.margin = unit(c(0.2, 0.02, 0.2, 0.2),"cm")),
  
  
  # Swedish Peoples Party: Welfare retrenchment
  ggplot(filter(barplot.data, Reform == "Retirement Tube" & Group == "Swedish Peoples Party"), 
         aes(x = Answer, y = Share, group = Round, fill = Round)) + 
    # Grid
    geom_hline(yintercept = seq(5, 65, 5), color = "grey90") +
    
    # Bars
    geom_bar(stat = "identity",
             position = position_dodge(),
             color = "black",
             alpha = 0.66) +
    geom_text(aes(label = paste0(Share, "%\nN=", n)), 
              color = "black", 
              size = 2.8, 
              position = position_dodge(0.9), 
              alpha = 0.85, 
              vjust = -0.25, 
              lineheight = 0.8) +
    scale_fill_manual(values = rep(c("#969696", "#525252"), times = 4)) +
    
    # Specs
    scale_y_continuous(breaks = seq(0, 70, 10), labels = c("0%", "10%", "20%", "30%", "40%", "50%", "60%", "70%")) +
    scale_x_continuous(breaks = c(1, 2, 3, 4), 
                       labels = c("Strongly\ndisagree","Disagree", "Agree", "Strongly\nagree")) +
    labs(x = NULL, y = NULL, fill = NULL) +
    coord_cartesian(xlim = c(0.35, 4.65), ylim = c(0, 70), expand = FALSE, clip = "off") +
    theme(text = element_text(color = "black"),
          legend.spacing.y = unit(0.25, "cm"),
          legend.key.size = unit(0.65, "cm"),
          panel.grid = element_blank(), 
          panel.background = element_rect(fill = "white"),
          plot.background = element_rect(fill = "white"),
          panel.border = element_rect(fill = "transparent"),
          axis.ticks = element_blank(),
          plot.margin = unit(c(0.2, 0.02, 0.2, 0.2),"cm")),
  
  
  # Swedish Peoples Party: Welfare expansion
  ggplot(filter(barplot.data, Reform == "Compulsory Schooling" & Group == "Swedish Peoples Party"), 
         aes(x = Answer, y = Share, group = Round, fill = Round)) + 
    # Grid
    geom_hline(yintercept = seq(5, 65, 5), color = "grey90") +
    geom_hline(yintercept = 70) +
    
    # Bars
    geom_bar(stat = "identity",
             position = position_dodge(),
             color = "black",
             alpha = 0.66) +
    geom_text(aes(label = paste0(Share, "%\nN=", n)), 
              color = "black", 
              size = 2.8, 
              position = position_dodge(0.9), 
              alpha = 0.85, 
              vjust = -0.25, 
              lineheight = 0.8) +
    scale_fill_manual(values = rep(c("#969696", "#525252"), times = 4)) +
    
    # Right panel
    geom_rect(xmin = 4.65, xmax = 5.05, ymin = 0, ymax = 70, colour = "black", fill = "grey90") +
    annotate("text", x = 4.85, y = 35, label = "Swedish People's Party", angle = 270, size = 12/.pt, fontface = "bold") +
    
    # Specs
    scale_y_continuous(breaks = seq(0, 70, 10), labels = c("0%", "10%", "20%", "30%", "40%", "50%", "60%", "70%")) +
    scale_x_continuous(breaks = c(1, 2, 3, 4), labels = c("Strongly\ndisagree","Disagree", "Agree", "Strongly\nagree")) +
    geom_hline(yintercept = 0) + geom_vline(xintercept = 0.35) +
    labs(x = NULL, y = NULL, fill = NULL) +
    coord_cartesian(xlim = c(0.35, 5.05), ylim = c(0, 70), expand = FALSE, clip = "off") +
    theme(text = element_text(color = "black"),
          axis.text.y = element_blank(),
          legend.spacing.y = unit(0.25, "cm"),
          legend.key.size = unit(0.65, "cm"),
          panel.grid = element_blank(), 
          panel.background = element_rect(fill = "white"),
          plot.background = element_rect(fill = "white"),
          panel.border = element_rect(color = "transparent", fill = "transparent"),
          axis.ticks = element_blank(),
          plot.margin = unit(c(0.2, 0.02, 0.2, 0.2),"cm")),
  
  ncol = 2, widths = c(4.95, 5.05),
  nrow = 5, heights = c(10, 9, 9, 9, 10),
  common.legend = TRUE, legend = "right") + 
  
  theme(panel.background = element_rect(color = "white", fill = "white"),
        plot.background = element_rect(color = "white", fill = "white"))



# Saving the output
ggsave(filename = "02-figures and models/Fig B1a - barplots - gov parties.png",
       width = 25, height = 30, units = "cm", dpi = 600) 








# __ Opposition voters ----------------------------------------------------

ggarrange(
  
  # National Coalition: Welfare retrenchment
  ggplot(filter(barplot.data, Reform == "Retirement Tube" & Group == "National Coalition"), 
         aes(x = Answer, y = Share, group = Round, fill = Round)) + 
    # Grid
    geom_hline(yintercept = seq(5, 65, 5), color = "grey90") +
    
    # Bars
    geom_bar(stat = "identity",
             position = position_dodge(),
             color = "black",
             alpha = 0.66) +
    geom_text(aes(label = paste0(Share, "%\nN=", n)), 
              color = "black", 
              size = 2.8, 
              position = position_dodge(0.9), 
              alpha = 0.85, 
              vjust = -0.25, 
              lineheight = 0.8) +
    scale_fill_manual(values = rep(c("#F0F0F0","#BDBDBD"), times = 4)) +
    
    # Header
    geom_rect(xmin = 0.35, xmax = 4.65, ymin = 70, ymax = 85, colour = "black", fill = "grey90") +
    annotate("text", x = 2.5, y = 77.5, hjust = 0.5, vjust = -0.15, label = "Welfare retrenchment", size = 12/.pt, fontface = "bold") +
    annotate("text", x = 2.5, y = 77.5, hjust = 0.5, vjust =  1.45, label = "Abolition of the 'retirement tube'", size = 8.5/.pt) +
    
    # Specs
    scale_y_continuous(breaks = seq(0, 70, 10), labels = c("0%", "10%", "20%", "30%", "40%", "50%", "60%", "70%")) +
    scale_x_continuous(breaks = c(1, 2, 3, 4), 
                       labels = c("Strongly\ndisagree","Disagree", "Agree", "Strongly\nagree")) +
    labs(x = NULL, y = NULL, fill = NULL) +
    coord_cartesian(xlim = c(0.35, 4.65), ylim = c(0, 85), expand = FALSE, clip = "off") +
    theme(text = element_text(color = "black"),
          axis.text.x = element_blank(),
          legend.spacing.y = unit(0.25, "cm"),
          legend.key.size = unit(0.65, "cm"),
          panel.grid = element_blank(), 
          panel.background = element_rect(fill = "white"),
          plot.background = element_rect(fill = "white"),
          panel.border = element_rect(fill = "transparent"),
          axis.ticks = element_blank(),
          plot.margin = unit(c(0.2, 0.02, 0.2, 0.2),"cm")),
  
  
  # National Coalition: Welfare expansion
  ggplot(filter(barplot.data, Reform == "Compulsory Schooling" & Group == "National Coalition"), 
         aes(x = Answer, y = Share, group = Round, fill = Round)) + 
    # Grid
    geom_hline(yintercept = seq(5, 65, 5), color = "grey90") +
    geom_hline(yintercept = 70) +
    
    # Bars
    geom_bar(stat = "identity",
             position = position_dodge(),
             color = "black",
             alpha = 0.66) +
    geom_text(aes(label = paste0(Share, "%\nN=", n)), 
              color = "black", 
              size = 2.8, 
              position = position_dodge(0.9), 
              alpha = 0.85, 
              vjust = -0.25, 
              lineheight = 0.8) +
    scale_fill_manual(values = rep(c("#F0F0F0","#BDBDBD"), times = 4)) +
    
    # Header
    geom_rect(xmin = 0.35, xmax = 4.65, ymin = 70, ymax = 85, colour = "black", fill = "grey90") +
    annotate("text", x = 2.5, y = 77.5, hjust = 0.5, vjust = -0.15, label = "Welfare expansion", size = 12/.pt, fontface = "bold") +
    annotate("text", x = 2.5, y = 77.5, hjust = 0.5, vjust =  1.45, label = "Extension of the compulsory school age", size = 8.5/.pt) +
    
    # Right panel
    geom_rect(xmin = 4.65, xmax = 5.05, ymin = 0, ymax = 70, colour = "black", fill = "grey90") +
    annotate("text", x = 4.85, y = 35, label = "National Coalition", angle = 270, size = 12/.pt, fontface = "bold") +
    
    # Specs
    scale_y_continuous(breaks = seq(0, 70, 10), labels = c("0%", "10%", "20%", "30%", "40%", "50%", "60%", "70%")) +
    scale_x_continuous(breaks = c(1, 2, 3, 4), labels = c("Strongly\ndisagree","Disagree", "Agree", "Strongly\nagree")) +
    geom_hline(yintercept = 0) + geom_vline(xintercept = 0.35) +
    labs(x = NULL, y = NULL, fill = NULL) +
    coord_cartesian(xlim = c(0.35, 5.05), ylim = c(0, 85), expand = FALSE, clip = "off") +
    theme(text = element_text(color = "black"),
          axis.text.x = element_blank(),
          axis.text.y = element_blank(),
          legend.spacing.y = unit(0.25, "cm"),
          legend.key.size = unit(0.65, "cm"),
          panel.grid = element_blank(), 
          panel.background = element_rect(fill = "white"),
          plot.background = element_rect(fill = "white"),
          panel.border = element_rect(color = "transparent", fill = "transparent"),
          axis.ticks = element_blank(),
          plot.margin = unit(c(0.2, 0.02, 0.2, 0.2),"cm")),
  
  
  # True Finns: Welfare retrenchment
  ggplot(filter(barplot.data, Reform == "Retirement Tube" & Group == "True Finns"), 
         aes(x = Answer, y = Share, group = Round, fill = Round)) + 
    # Grid
    geom_hline(yintercept = seq(5, 65, 5), color = "grey90") +
    
    # Bars
    geom_bar(stat = "identity",
             position = position_dodge(),
             color = "black",
             alpha = 0.66) +
    geom_text(aes(label = paste0(Share, "%\nN=", n)), 
              color = "black", 
              size = 2.8, 
              position = position_dodge(0.9), 
              alpha = 0.85, 
              vjust = -0.25, 
              lineheight = 0.8) +
    scale_fill_manual(values = rep(c("#F0F0F0","#BDBDBD"), times = 4)) +
    
    # Specs
    scale_y_continuous(breaks = seq(0, 70, 10), labels = c("0%", "10%", "20%", "30%", "40%", "50%", "60%", "70%")) +
    scale_x_continuous(breaks = c(1, 2, 3, 4), 
                       labels = c("Strongly\ndisagree","Disagree", "Agree", "Strongly\nagree")) +
    labs(x = NULL, y = NULL, fill = NULL) +
    coord_cartesian(xlim = c(0.35, 4.65), ylim = c(0, 70), expand = FALSE, clip = "off") +
    theme(text = element_text(color = "black"),
          axis.text.x = element_blank(),
          legend.spacing.y = unit(0.25, "cm"),
          legend.key.size = unit(0.65, "cm"),
          panel.grid = element_blank(), 
          panel.background = element_rect(fill = "white"),
          plot.background = element_rect(fill = "white"),
          panel.border = element_rect(fill = "transparent"),
          axis.ticks = element_blank(),
          plot.margin = unit(c(0.2, 0.02, 0.2, 0.2),"cm")),
  
  
  # True Finns: Welfare expansion
  ggplot(filter(barplot.data, Reform == "Compulsory Schooling" & Group == "True Finns"), 
         aes(x = Answer, y = Share, group = Round, fill = Round)) + 
    # Grid
    geom_hline(yintercept = seq(5, 65, 5), color = "grey90") +
    geom_hline(yintercept = 70) +
    
    # Bars
    geom_bar(stat = "identity",
             position = position_dodge(),
             color = "black",
             alpha = 0.66) +
    geom_text(aes(label = paste0(Share, "%\nN=", n)), 
              color = "black", 
              size = 2.8, 
              position = position_dodge(0.9), 
              alpha = 0.85, 
              vjust = -0.25, 
              lineheight = 0.8) +
    scale_fill_manual(values = rep(c("#F0F0F0","#BDBDBD"), times = 4)) +
    
    # Right panel
    geom_rect(xmin = 4.65, xmax = 5.05, ymin = 0, ymax = 70, colour = "black", fill = "grey90") +
    annotate("text", x = 4.85, y = 35, label = "True Finns", angle = 270, size = 12/.pt, fontface = "bold") +
    
    # Specs
    scale_y_continuous(breaks = seq(0, 70, 10), labels = c("0%", "10%", "20%", "30%", "40%", "50%", "60%", "70%")) +
    scale_x_continuous(breaks = c(1, 2, 3, 4), labels = c("Strongly\ndisagree","Disagree", "Agree", "Strongly\nagree")) +
    geom_hline(yintercept = 0) + geom_vline(xintercept = 0.35) +
    labs(x = NULL, y = NULL, fill = NULL) +
    coord_cartesian(xlim = c(0.35, 5.05), ylim = c(0, 70), expand = FALSE, clip = "off") +
    theme(text = element_text(color = "black"),
          axis.text.x = element_blank(),
          axis.text.y = element_blank(),
          legend.spacing.y = unit(0.25, "cm"),
          legend.key.size = unit(0.65, "cm"),
          panel.grid = element_blank(), 
          panel.background = element_rect(fill = "white"),
          plot.background = element_rect(fill = "white"),
          panel.border = element_rect(color = "transparent", fill = "transparent"),
          axis.ticks = element_blank(),
          plot.margin = unit(c(0.2, 0.02, 0.2, 0.2),"cm")),
  
  
  # Christian Democrats: Welfare retrenchment
  ggplot(filter(barplot.data, Reform == "Retirement Tube" & Group == "Christian Democrats"), 
         aes(x = Answer, y = Share, group = Round, fill = Round)) + 
    # Grid
    geom_hline(yintercept = seq(5, 65, 5), color = "grey90") +
    
    # Bars
    geom_bar(stat = "identity",
             position = position_dodge(),
             color = "black",
             alpha = 0.66) +
    geom_text(aes(label = paste0(Share, "%\nN=", n)), 
              color = "black", 
              size = 2.8, 
              position = position_dodge(0.9), 
              alpha = 0.85, 
              vjust = -0.25, 
              lineheight = 0.8) +
    scale_fill_manual(values = rep(c("#F0F0F0","#BDBDBD"), times = 4)) +
    
    # Specs
    scale_y_continuous(breaks = seq(0, 70, 10), labels = c("0%", "10%", "20%", "30%", "40%", "50%", "60%", "70%")) +
    scale_x_continuous(breaks = c(1, 2, 3, 4), 
                       labels = c("Strongly\ndisagree","Disagree", "Agree", "Strongly\nagree")) +
    labs(x = NULL, y = NULL, fill = NULL) +
    coord_cartesian(xlim = c(0.35, 4.65), ylim = c(0, 70), expand = FALSE, clip = "off") +
    theme(text = element_text(color = "black"),
          axis.text.x = element_blank(),
          legend.spacing.y = unit(0.25, "cm"),
          legend.key.size = unit(0.65, "cm"),
          panel.grid = element_blank(), 
          panel.background = element_rect(fill = "white"),
          plot.background = element_rect(fill = "white"),
          panel.border = element_rect(fill = "transparent"),
          axis.ticks = element_blank(),
          plot.margin = unit(c(0.2, 0.02, 0.2, 0.2),"cm")),
  
  
  # Christian Democrats: Welfare expansion
  ggplot(filter(barplot.data, Reform == "Compulsory Schooling" & Group == "Christian Democrats"), 
         aes(x = Answer, y = Share, group = Round, fill = Round)) + 
    # Grid
    geom_hline(yintercept = seq(5, 65, 5), color = "grey90") +
    geom_hline(yintercept = 70) +
    
    # Bars
    geom_bar(stat = "identity",
             position = position_dodge(),
             color = "black",
             alpha = 0.66) +
    geom_text(aes(label = paste0(Share, "%\nN=", n)), 
              color = "black", 
              size = 2.8, 
              position = position_dodge(0.9), 
              alpha = 0.85, 
              vjust = -0.25, 
              lineheight = 0.8) +
    scale_fill_manual(values = rep(c("#F0F0F0","#BDBDBD"), times = 4)) +
    
    # Right panel
    geom_rect(xmin = 4.65, xmax = 5.05, ymin = 0, ymax = 70, colour = "black", fill = "grey90") +
    annotate("text", x = 4.85, y = 35, label = "Christian Democrats", angle = 270, size = 12/.pt, fontface = "bold") +
    
    # Specs
    scale_y_continuous(breaks = seq(0, 70, 10), labels = c("0%", "10%", "20%", "30%", "40%", "50%", "60%", "70%")) +
    scale_x_continuous(breaks = c(1, 2, 3, 4), labels = c("Strongly\ndisagree","Disagree", "Agree", "Strongly\nagree")) +
    geom_hline(yintercept = 0) + geom_vline(xintercept = 0.35) +
    labs(x = NULL, y = NULL, fill = NULL) +
    coord_cartesian(xlim = c(0.35, 5.05), ylim = c(0, 70), expand = FALSE, clip = "off") +
    theme(text = element_text(color = "black"),
          axis.text.x = element_blank(),
          axis.text.y = element_blank(),
          legend.spacing.y = unit(0.25, "cm"),
          legend.key.size = unit(0.65, "cm"),
          panel.grid = element_blank(), 
          panel.background = element_rect(fill = "white"),
          plot.background = element_rect(fill = "white"),
          panel.border = element_rect(color = "transparent", fill = "transparent"),
          axis.ticks = element_blank(),
          plot.margin = unit(c(0.2, 0.02, 0.2, 0.2),"cm")),
  
  
  # Movement Now: Welfare retrenchment
  ggplot(filter(barplot.data, Reform == "Retirement Tube" & Group == "Movement Now"), 
         aes(x = Answer, y = Share, group = Round, fill = Round)) + 
    # Grid
    geom_hline(yintercept = seq(5, 65, 5), color = "grey90") +
    
    # Bars
    geom_bar(stat = "identity",
             position = position_dodge(),
             color = "black",
             alpha = 0.66) +
    geom_text(aes(label = paste0(Share, "%\nN=", n)), 
              color = "black", 
              size = 2.8, 
              position = position_dodge(0.9), 
              alpha = 0.85, 
              vjust = -0.25, 
              lineheight = 0.8) +
    scale_fill_manual(values = rep(c("#F0F0F0","#BDBDBD"), times = 4)) +
    
    # Specs
    scale_y_continuous(breaks = seq(0, 70, 10), labels = c("0%", "10%", "20%", "30%", "40%", "50%", "60%", "70%")) +
    scale_x_continuous(breaks = c(1, 2, 3, 4), 
                       labels = c("Strongly\ndisagree","Disagree", "Agree", "Strongly\nagree")) +
    labs(x = NULL, y = NULL, fill = NULL) +
    coord_cartesian(xlim = c(0.35, 4.65), ylim = c(0, 70), expand = FALSE, clip = "off") +
    theme(text = element_text(color = "black"),
          axis.text.x = element_blank(),
          legend.spacing.y = unit(0.25, "cm"),
          legend.key.size = unit(0.65, "cm"),
          panel.grid = element_blank(), 
          panel.background = element_rect(fill = "white"),
          plot.background = element_rect(fill = "white"),
          panel.border = element_rect(fill = "transparent"),
          axis.ticks = element_blank(),
          plot.margin = unit(c(0.2, 0.02, 0.2, 0.2),"cm")),
  
  
  # Movement Now: Welfare expansion
  ggplot(filter(barplot.data, Reform == "Compulsory Schooling" & Group == "Movement Now"), 
         aes(x = Answer, y = Share, group = Round, fill = Round)) + 
    # Grid
    geom_hline(yintercept = seq(5, 65, 5), color = "grey90") +
    geom_hline(yintercept = 70) +
    
    # Bars
    geom_bar(stat = "identity",
             position = position_dodge(),
             color = "black",
             alpha = 0.66) +
    geom_text(aes(label = paste0(Share, "%\nN=", n)), 
              color = "black", 
              size = 2.8, 
              position = position_dodge(0.9), 
              alpha = 0.85, 
              vjust = -0.25, 
              lineheight = 0.8) +
    scale_fill_manual(values = rep(c("#F0F0F0","#BDBDBD"), times = 4)) +
    
    # Right panel
    geom_rect(xmin = 4.65, xmax = 5.05, ymin = 0, ymax = 70, colour = "black", fill = "grey90") +
    annotate("text", x = 4.85, y = 35, label = "Movement Now", angle = 270, size = 12/.pt, fontface = "bold") +
    
    # Specs
    scale_y_continuous(breaks = seq(0, 70, 10), labels = c("0%", "10%", "20%", "30%", "40%", "50%", "60%", "70%")) +
    scale_x_continuous(breaks = c(1, 2, 3, 4), labels = c("Strongly\ndisagree","Disagree", "Agree", "Strongly\nagree")) +
    geom_hline(yintercept = 0) + geom_vline(xintercept = 0.35) +
    labs(x = NULL, y = NULL, fill = NULL) +
    coord_cartesian(xlim = c(0.35, 5.05), ylim = c(0, 70), expand = FALSE, clip = "off") +
    theme(text = element_text(color = "black"),
          axis.text.x = element_blank(),
          axis.text.y = element_blank(),
          legend.spacing.y = unit(0.25, "cm"),
          legend.key.size = unit(0.65, "cm"),
          panel.grid = element_blank(), 
          panel.background = element_rect(fill = "white"),
          plot.background = element_rect(fill = "white"),
          panel.border = element_rect(color = "transparent", fill = "transparent"),
          axis.ticks = element_blank(),
          plot.margin = unit(c(0.2, 0.02, 0.2, 0.2),"cm")),
  
  
  # Other: Welfare retrenchment
  ggplot(filter(barplot.data, Reform == "Retirement Tube" & Group == "Other"), 
         aes(x = Answer, y = Share, group = Round, fill = Round)) + 
    # Grid
    geom_hline(yintercept = seq(5, 65, 5), color = "grey90") +
    
    # Bars
    geom_bar(stat = "identity",
             position = position_dodge(),
             color = "black",
             alpha = 0.66) +
    geom_text(aes(label = paste0(Share, "%\nN=", n)), 
              color = "black", 
              size = 2.8, 
              position = position_dodge(0.9), 
              alpha = 0.85, 
              vjust = -0.25, 
              lineheight = 0.8) +
    scale_fill_manual(values = rep(c("#F0F0F0","#BDBDBD"), times = 4)) +
    
    # Specs
    scale_y_continuous(breaks = seq(0, 70, 10), labels = c("0%", "10%", "20%", "30%", "40%", "50%", "60%", "70%")) +
    scale_x_continuous(breaks = c(1, 2, 3, 4), 
                       labels = c("Strongly\ndisagree","Disagree", "Agree", "Strongly\nagree")) +
    labs(x = NULL, y = NULL, fill = NULL) +
    coord_cartesian(xlim = c(0.35, 4.65), ylim = c(0, 70), expand = FALSE, clip = "off") +
    theme(text = element_text(color = "black"),
          legend.spacing.y = unit(0.25, "cm"),
          legend.key.size = unit(0.65, "cm"),
          panel.grid = element_blank(), 
          panel.background = element_rect(fill = "white"),
          plot.background = element_rect(fill = "white"),
          panel.border = element_rect(fill = "transparent"),
          axis.ticks = element_blank(),
          plot.margin = unit(c(0.2, 0.02, 0.2, 0.2),"cm")),
  
  
  # Other: Welfare expansion
  ggplot(filter(barplot.data, Reform == "Compulsory Schooling" & Group == "Other"), 
         aes(x = Answer, y = Share, group = Round, fill = Round)) + 
    # Grid
    geom_hline(yintercept = seq(5, 65, 5), color = "grey90") +
    geom_hline(yintercept = 70) +
    
    # Bars
    geom_bar(stat = "identity",
             position = position_dodge(),
             color = "black",
             alpha = 0.66) +
    geom_text(aes(label = paste0(Share, "%\nN=", n)), 
              color = "black", 
              size = 2.8, 
              position = position_dodge(0.9), 
              alpha = 0.85, 
              vjust = -0.25, 
              lineheight = 0.8) +
    scale_fill_manual(values = rep(c("#F0F0F0","#BDBDBD"), times = 4)) +
    
    # Right panel
    geom_rect(xmin = 4.65, xmax = 5.05, ymin = 0, ymax = 70, colour = "black", fill = "grey90") +
    annotate("text", x = 4.85, y = 35, label = "Other", angle = 270, size = 12/.pt, fontface = "bold") +
    
    # Specs
    scale_y_continuous(breaks = seq(0, 70, 10), labels = c("0%", "10%", "20%", "30%", "40%", "50%", "60%", "70%")) +
    scale_x_continuous(breaks = c(1, 2, 3, 4), labels = c("Strongly\ndisagree","Disagree", "Agree", "Strongly\nagree")) +
    geom_hline(yintercept = 0) + geom_vline(xintercept = 0.35) +
    labs(x = NULL, y = NULL, fill = NULL) +
    coord_cartesian(xlim = c(0.35, 5.05), ylim = c(0, 70), expand = FALSE, clip = "off") +
    theme(text = element_text(color = "black"),
          axis.text.y = element_blank(),
          legend.spacing.y = unit(0.25, "cm"),
          legend.key.size = unit(0.65, "cm"),
          panel.grid = element_blank(), 
          panel.background = element_rect(fill = "white"),
          plot.background = element_rect(fill = "white"),
          panel.border = element_rect(color = "transparent", fill = "transparent"),
          axis.ticks = element_blank(),
          plot.margin = unit(c(0.2, 0.02, 0.2, 0.2),"cm")),
  
  ncol = 2, widths = c(4.95, 5.05),
  nrow = 5, heights = c(10, 9, 9, 9, 10),
  common.legend = TRUE, legend = "right") + 
  
  theme(panel.background = element_rect(color = "white", fill = "white"),
        plot.background = element_rect(color = "white", fill = "white"))



# Saving the output
ggsave(filename = "02-figures and models/Fig B1b - barplots - opp parties.png",
       width = 25, height = 30, units = "cm", dpi = 600) 






# FIGURE B2 ---------------------------------------------------------------
# NOTE: The following section generates Figure B2 - i.e., a bar plot showing
#       the distribution of individual responses about policy preferences
#       among government vs opposition voters across two waves



# _ Subsetting relevant data ----------------------------------------------
# NOTE: Used are only observations of those participants for whom dataset
#       includes information on party vote (in both rounds) and left-right
#       ideology (in both rounds)
RETRENCHMENT.both.waves <- na.omit(BIBU.panel[c("GovParty", "RETIREMENT_TUBE_R1", "RETIREMENT_TUBE_R2")])
EXPANSION.both.waves <- na.omit(BIBU.panel[c("GovParty", "COMPULSORY_SCHOOLING_R1", "COMPULSORY_SCHOOLING_R2")])



# _ Generating data.frame with group totals -------------------------------
barplot.data <-
  rbind(
    # Welfare retrenchment: Round 1
    data.frame(
      RETRENCHMENT.both.waves %>%
        group_by(Group = GovParty) %>%
        count(Answer = RETIREMENT_TUBE_R1) %>%
        mutate(Group_total = sum(n)) %>%
        mutate(Share = round((n/Group_total)*100, 1)) %>%
        mutate(Reform = c("Retirement Tube"), .before = Group) %>%
        mutate(Round = c("Round 1"), .before = Group)),
    
    # Welfare retrenchment: Round 2
    data.frame(
      RETRENCHMENT.both.waves %>%
        group_by(Group = GovParty) %>%
        count(Answer = RETIREMENT_TUBE_R2) %>%
        mutate(Group_total = sum(n)) %>%
        mutate(Share = round((n/Group_total)*100, 1)) %>%
        mutate(Reform = c("Retirement Tube"), .before = Group) %>%
        mutate(Round = c("Round 2"), .before = Group)),
    
    # Welfare expansion: Round 1
    data.frame(
      EXPANSION.both.waves %>%
        group_by(Group = GovParty) %>%
        count(Answer = COMPULSORY_SCHOOLING_R1) %>%
        mutate(Group_total = sum(n)) %>%
        mutate(Share = round((n/Group_total)*100, 1)) %>%
        mutate(Reform = c("Compulsory Schooling"), .before = Group) %>%
        mutate(Round = c("Round 1"), .before = Group)),
    
    # Welfare expansion: Round 2
    data.frame(
      EXPANSION.both.waves %>%
        group_by(Group = GovParty) %>%
        count(Answer = COMPULSORY_SCHOOLING_R2) %>%
        mutate(Group_total = sum(n)) %>%
        mutate(Share = round((n/Group_total)*100, 1)) %>%
        mutate(Reform = c("Compulsory Schooling"), .before = Group) %>%
        mutate(Round = c("Round 2"), .before = Group))
  )


# Interim cleanup
rm(RETRENCHMENT.both.waves, 
   EXPANSION.both.waves)



# _ Barplot ---------------------------------------------------------------

# __ Government voters ----------------------------------------------------
government <-
  ggarrange(
    
    # Welfare retrenchment
    ggplot(filter(barplot.data, Reform == "Retirement Tube" & Group == "Government voters"), 
           aes(x = Answer, y = Share, group = Round, fill = Round)) + 
      # Grid
      geom_hline(yintercept = seq(5, 45, 5), color = "grey90") +
      
      # Bars
      geom_bar(stat = "identity",
               position = position_dodge(),
               color = "black",
               alpha = 0.66) +
      geom_text(aes(label = paste0(Share, "%\nN=", n)), 
                color = "black", 
                size = 2.75, 
                position = position_dodge(0.9), 
                alpha = 0.85, 
                vjust = 1.25, 
                lineheight = 0.85) +
      scale_fill_manual(values = rep(c("#969696", "#525252"), times = 4)) +
      
      # Header
      geom_rect(xmin = 0.35, xmax = 4.65, ymin = 50, ymax = 60, colour = "black", fill = "grey90") +
      annotate("text", x = 2.5, y = 55, hjust = 0.5, vjust = -0.15, label = "Welfare retrenchment", size = 12/.pt, fontface = "bold") +
      annotate("text", x = 2.5, y = 55, hjust = 0.5, vjust =  1.45, label = "Abolition of the 'retirement tube'", size = 8.5/.pt) +
      
      # Specs
      scale_y_continuous(breaks = seq(0, 50, 10),
                         labels = c("0%", "10%", "20%", "30%", "40%", "50%")) +
      scale_x_continuous(breaks = c(1, 2, 3, 4), 
                         labels = c("Strongly\ndisagree","Disagree", "Agree", "Strongly\nagree")) +
      labs(x = NULL, y = NULL, fill = NULL) +
      coord_cartesian(xlim = c(0.35, 4.65), ylim = c(0, 60), expand = FALSE, clip = "off") +
      theme(text = element_text(color = "black"),
            axis.text.x = element_blank(),
            legend.spacing.y = unit(0.25, "cm"),
            legend.key.size = unit(0.65, "cm"),
            panel.grid = element_blank(), 
            panel.background = element_rect(fill = "white"),
            plot.background = element_rect(fill = "white"),
            panel.border = element_rect(fill = "transparent"),
            axis.ticks = element_blank(),
            plot.margin = unit(c(0.2, 0.02, 0.2, 0.2),"cm")),
    
    
    # Welfare expansion
    ggplot(filter(barplot.data, Reform == "Compulsory Schooling" & Group == "Government voters"), 
           aes(x = Answer, y = Share, group = Round, fill = Round)) + 
      # Grid
      geom_hline(yintercept = seq(5, 45, 5), color = "grey90") +
      
      # Bars
      geom_bar(stat = "identity",
               position = position_dodge(),
               color = "black",
               alpha = 0.66) +
      geom_text(aes(label = paste0(Share, "%\nN=", n)), 
                color = "black", 
                size = 2.75, 
                position = position_dodge(0.9), 
                alpha = 0.85, 
                vjust = 1.25, 
                lineheight = 0.85) +
      scale_fill_manual(values = rep(c("#969696", "#525252"), times = 4)) +
      
      # Header
      geom_rect(xmin = 0.35, xmax = 4.65, ymin = 50, ymax = 60, colour = "black", fill = "grey90") +
      annotate("text", x = 2.5, y = 55, hjust = 0.5, vjust = -0.15, label = "Welfare expansion", size = 12/.pt, fontface = "bold") +
      annotate("text", x = 2.5, y = 55, hjust = 0.5, vjust =  1.45, label = "Extension of the compulsory school age", size = 8.5/.pt) +
      
      # Right panel
      geom_rect(xmin = 4.65, xmax = 5.05, ymin = 0, ymax = 50, colour = "black", fill = "grey90") +
      annotate("text", x = 4.85, y = 25, label = "Government voters", angle = 270, size = 12/.pt, fontface = "bold") +
      
      # Specs
      scale_y_continuous(breaks = seq(0, 50, 10), labels = c("0%", "10%", "20%", "30%", "40%", "50%")) +
      scale_x_continuous(breaks = c(1, 2, 3, 4), labels = c("Strongly\ndisagree","Disagree", "Agree", "Strongly\nagree")) +
      geom_hline(yintercept = 0) + geom_vline(xintercept = 0.35) +
      labs(x = NULL, y = NULL, fill = NULL) +
      coord_cartesian(xlim = c(0.35, 5.05), ylim = c(0, 60), expand = FALSE, clip = "off") +
      theme(text = element_text(color = "black"),
            axis.text.x = element_blank(),
            axis.text.y = element_blank(),
            legend.spacing.y = unit(0.25, "cm"),
            legend.key.size = unit(0.65, "cm"),
            panel.grid = element_blank(), 
            panel.background = element_rect(fill = "white"),
            plot.background = element_rect(fill = "white"),
            panel.border = element_rect(color = "transparent", fill = "transparent"),
            axis.ticks = element_blank(),
            plot.margin = unit(c(0.2, 0.02, 0.2, 0.2),"cm")),
    
    ncol = 2, widths = c(4.95, 5.05),
    common.legend = TRUE, legend = "right")



# __ Opposition voters ----------------------------------------------------
opposition <- 
  ggarrange(
    
    # Welfare retrenchment
    ggplot(filter(barplot.data, Reform == "Retirement Tube" & Group == "Opposition voters"), 
           aes(x = Answer, y = Share, group = Round, fill = Round)) + 
      # Grid
      geom_hline(yintercept = seq(5, 45, 5), color = "grey90") +
      
      # Bars
      geom_bar(stat = "identity",
               position = position_dodge(),
               color = "black",
               alpha = 0.66) +
      geom_text(aes(label = paste0(Share, "%\nN=", n)), 
                color = "black", 
                size = 2.75, 
                position = position_dodge(0.9), 
                alpha = 0.85, 
                vjust = 1.25, 
                lineheight = 0.85) +
      scale_fill_manual(values = rep(c("#F0F0F0","#BDBDBD"), times = 4)) +
      
      # Specs
      scale_y_continuous(breaks = seq(0, 50, 10),
                         labels = c("0%", "10%", "20%", "30%", "40%", "50%")) +
      scale_x_continuous(breaks = c(1, 2, 3, 4), 
                         labels = c("Strongly\ndisagree","Disagree", "Agree", "Strongly\nagree")) +
      labs(x = NULL, y = NULL, fill = NULL) +
      coord_cartesian(xlim = c(0.35, 4.65), ylim = c(0, 50), expand = FALSE, clip = "off") +
      theme(text = element_text(color = "black"),
            axis.text.x = element_text(size = 10, vjust = 0.5),
            legend.spacing.y = unit(0.25, "cm"),
            legend.key.size = unit(0.65, "cm"),
            panel.grid = element_blank(), 
            panel.background = element_rect(fill = "white"),
            plot.background = element_rect(fill = "white"),
            panel.border = element_rect(fill = "transparent"),
            axis.ticks = element_blank(),
            plot.margin = unit(c(0.2, 0.02, 0.2, 0.2),"cm")),
    
    
    # Welfare expansion
    ggplot(filter(barplot.data, Reform == "Compulsory Schooling" & Group == "Opposition voters"), 
           aes(x = Answer, y = Share, group = Round, fill = Round)) + 
      # Grid
      geom_hline(yintercept = seq(5, 45, 5), color = "grey90") +
      
      # Bars
      geom_bar(stat = "identity",
               position = position_dodge(),
               color = "black",
               alpha = 0.66) +
      geom_text(aes(label = paste0(Share, "%\nN=", n)), 
                color = "black", 
                size = 2.75, 
                position = position_dodge(0.9), 
                alpha = 0.85, 
                vjust = 1.25, 
                lineheight = 0.85) +
      scale_fill_manual(values = rep(c("#F0F0F0","#BDBDBD"), times = 4)) +
      
      # Right panel
      geom_rect(xmin = 4.65, xmax = 5.05, ymin = 0, ymax = 50, colour = "black", fill = "grey90") +
      annotate("text", x = 4.85, y = 25, label = "Opposition voters", angle = 270, size = 12/.pt, fontface = "bold") +
      
      # Specs
      scale_y_continuous(breaks = seq(0, 50, 10), labels = c("0%", "10%", "20%", "30%", "40%", "50%")) +
      scale_x_continuous(breaks = c(1, 2, 3, 4), labels = c("Strongly\ndisagree","Disagree", "Agree", "Strongly\nagree")) +
      geom_hline(yintercept = c(0, 50)) + geom_vline(xintercept = 0.35) +
      labs(x = NULL, y = NULL, fill = NULL) +
      coord_cartesian(xlim = c(0.35, 5.05), ylim = c(0, 50), expand = FALSE, clip = "off") +
      theme(text = element_text(color = "black"),
            axis.text.x = element_text(size = 10, vjust = 0.5),
            axis.text.y = element_blank(),
            legend.spacing.y = unit(0.25, "cm"),
            legend.key.size = unit(0.65, "cm"),
            panel.grid = element_blank(), 
            panel.background = element_rect(fill = "white"),
            plot.background = element_rect(fill = "white"),
            panel.border = element_rect(color = "transparent", fill = "transparent"),
            axis.ticks = element_blank(),
            plot.margin = unit(c(0.2, 0.02, 0.2, 0.2),"cm")),
    
    ncol = 2, widths = c(4.95, 5.05),
    common.legend = TRUE, legend = "right")



# __ Merging the figures --------------------------------------------------
ggarrange(government, opposition, nrow = 2, heights = c(51.25, 50)) + 
  theme(panel.background = element_rect(color = "white", fill = "white"),
        plot.background = element_rect(color = "white", fill = "white"))



# Saving the output
ggsave(filename = "02-figures and models/Fig B2 - barplots - gov vs opp.png",
       width = 25, height = 13, units = "cm", dpi = 600)




# FINAL CLEANUP -----------------------------------------------------------
rm(barplot.data, government, opposition)
rm(BIBU.DiD, BIBU.panel)

